<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="common/header.jsp"%>
<div class="clearfix"></div>
<div class="row">
	<div class="col-md-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>
					APP 信息管理维护 <i class="fa fa-devUser"></i><small>${devUserSession.devName}
						- 您可以通过搜索或者其他的筛选项对APP的信息进行修改、删除等管理操作。^_^</small>
				</h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<form method="post" action="${pageContext.request.contextPath}/dev/devviewAppInfoList">
					<input type="hidden" name="currPageNo" value="1" />
			    <ul>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">软件名称</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<input name="devSoftwareName" type="text" class="form-control col-md-7 col-xs-12" value="${softwareName }">
							</div>
						</div>
					</li>
					
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">APP状态</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select id="devqueryStatus" name="devStatus" class="form-control">
									<option value="0">--请选择--</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">所属平台</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select id="flatformId" name="devFlatformId" class="form-control">
									<option value="0">--请选择--</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">一级分类</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select id="categoryLevel1" name="categoryLevel1" class="form-control">
									<option value="0">--请选择--</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">二级分类</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
							<input type="hidden" name="categorylevel2list" id="categorylevel2list"/>
        						<select name="categoryLevel2" id="categoryLevel2" class="form-control">
									<option value="0">--请选择--</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">三级分类</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
        						<select name="categoryLevel3" id="categoryLevel3" class="form-control">
									<option value="0">--请选择--</option>
        						</select>
							</div>
						</div>
					</li>
					<li><button type="submit" class="btn btn-primary"> 查 &nbsp;&nbsp;&nbsp;&nbsp;询 </button></li>
				</ul>
			</form>
		</div>
	</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
	<div class="x_panel">
		<div class="x_content">
			<p class="text-muted font-13 m-b-30"></p>
			<div id="datatable-responsive_wrapper"
				class="dataTables_wrapper form-inline dt-bootstrap no-footer">
				<div class="row">
					<div class="col-sm-12">
					<a href="${pageContext.request.contextPath}/dev/devxinzeng" class="btn btn-success btn-sm">新增APP基础信息</a>
						<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
							cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info" style="width: 100%;">
							<thead>
								<tr role="row">
									<th class="sorting_asc" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="First name: activate to sort column descending"
										aria-sort="ascending">软件名称</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										APK名称</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										软件大小(单位:M)</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										所属平台</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										所属分类(一级分类、二级分类、三级分类)</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										状态</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										下载次数</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										aria-label="Last name: activate to sort column ascending">
										最新版本号</th>
									<th class="sorting" tabindex="0"
										aria-controls="datatable-responsive" rowspan="1" colspan="1"
										style="width: 124px;"
										aria-label="Last name: activate to sort column ascending">
										操作</th>
								</tr>
							</thead>
							<tbody><c:forEach var="appInfo" items="${appInfoList }" varStatus="status">
								<tr role="row" class="odd">
									<td tabindex="0" class="sorting_1">${appInfo.softwareName}</td>
									<td>${appInfo.apkName }</td>
									<td>${appInfo.softwareSize }</td>
									<td>${appInfo.flatformName }</td>
									<td>${appInfo.categoryLevel1Name } -> ${appInfo.categoryLevel2Name } -> ${appInfo.categoryLevel3Name }</td>
									<td >
										<span id="appInfoStatus${appInfo.id}">${appInfo.statusName }</span></td>
									<td>${appInfo.downloads }</td>
									<td>${appInfo.versionNo }</td>
									<td>
										<div class="btn-group">
											<button type="button" class="btn btn-danger">点击操作</button>
											<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
												<span class="caret"></span>
												<span class="sr-only">Toggle Dropdown</span>
											</button>
											<ul class="dropdown-menu" role="menu">
												<li>
													<c:choose>
														<c:when test="${appInfo.status == 2 || appInfo.status == 5}">
															<a class="saleSwichOpen" saleSwitch="open" appinfoid=${appInfo.id }  appsoftwarename=${appInfo.softwareName } data-toggle="tooltip" data-placement="top" title="" data-original-title="恭喜您，您的审核已经通过，您可以点击上架发布您的APP">上架</a>
														</c:when>
														<c:when test="${appInfo.status == 4}">
															<a class="saleSwichClose" saleSwitch="close" appinfoid=${appInfo.id }  appsoftwarename=${appInfo.softwareName } data-toggle="tooltip" data-placement="top" title="" data-original-title="您可以点击下架来停止发布您的APP，市场将不提供APP的下载">下架</a>
														</c:when>
													</c:choose>
												</li>
												<li><a class="addVersion" appinfoid="${appInfo.id}" data-toggle="tooltip" data-placement="top" title="" data-original-title="新增APP版本信息">新增版本</a>
												</li>
												<li><a class="modifyVersion"
													   appinfoid="${appInfo.id }" versionid="${appInfo.versionId }" status="${appInfo.status }"
													   statusname="${appInfo.statusName }"
													   data-toggle="tooltip" data-placement="top" title="" data-original-title="修改APP最新版本信息">修改版本</a>
												</li>
												<li><a  class="modifyAppInfo"
														appinfoid="${appInfo.id }" status="${appInfo.status}" statusname="${appInfo.statusName }"
														data-toggle="tooltip" data-placement="top" title="" data-original-title="修改APP基础信息">修改</a></li>
												<li><a  class="viewApp" appinfoid=${appInfo.id }  data-toggle="tooltip" data-placement="top" title="" data-original-title="查看APP基础信息以及全部版本信息">查看</a></li>
												<li><a  class="deleteApp" appinfoid=${appInfo.id }  appsoftwarename=${appInfo.softwareName } data-toggle="tooltip" data-placement="top" title="" data-original-title="删除APP基础信息以及全部版本信息">删除</a></li>
											</ul>
										</div>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-5">
						<div class="dataTables_info" id="datatable-responsive_info"
							role="status" aria-live="polite">共${page.totalCount }条记录
							${page.currPageNo }/${page.totalPageCount }页</div>
					</div>
					<div class="col-sm-7">
						<div class="dataTables_paginate paging_simple_numbers"
							id="datatable-responsive_paginate">
							<ul class="pagination">
								<c:if test="${page.currPageNo > 1}">
									<li class="paginate_button previous"><a
											href="${pageContext.request.contextPath}/dev/devviewAppInfoList?softwareName=${softwareName}&flatformId=${flatformId}&categoryLevel1=${categoryLevel1}&categoryLevel2=${categoryLevel2}&categoryLevel3=${categoryLevel3}&currPageNo=1"
											aria-controls="datatable-responsive" data-dt-idx="0"
											tabindex="0">首页</a>
									</li>
									<li class="paginate_button "><a
											href="${pageContext.request.contextPath}/dev/devviewAppInfoList?softwareName=${softwareName}&flatformId=${flatformId}&categoryLevel1=${categoryLevel1}&categoryLevel2=${categoryLevel2}&categoryLevel3=${categoryLevel3}&currPageNo=${page.currPageNo-1}"
											aria-controls="datatable-responsive" data-dt-idx="1"
											tabindex="0">上一页</a>
									</li>
								</c:if>
								<c:if test="${page.currPageNo < page.totalPageCount }">
									<li class="paginate_button "><a
											href="${pageContext.request.contextPath}/dev/devviewAppInfoList?softwareName=${softwareName}&flatformId=${flatformId}&categoryLevel1=${categoryLevel1}&categoryLevel2=${categoryLevel2}&categoryLevel3=${categoryLevel3}&currPageNo=${page.currPageNo+1}"
											aria-controls="datatable-responsive" data-dt-idx="1"
											tabindex="0">下一页</a>
									</li>
									<li class="paginate_button next"><a
											href="${pageContext.request.contextPath}/dev/devviewAppInfoList?softwareName=${softwareName}&flatformId=${flatformId}&categoryLevel1=${categoryLevel1}&categoryLevel2=${categoryLevel2}&categoryLevel3=${categoryLevel3}&currPageNo=${page.totalPageCount}"
											aria-controls="datatable-responsive" data-dt-idx="7"
											tabindex="0">最后一页</a>
									</li>
								</c:if>
							</ul>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>
</div>
</div>
<%@include file="common/footer.jsp"%>
<script>
	$(function(){
		$("#flatformId").load("${pageContext.request.contextPath}/dev/devpingtaiName");
		$("#categoryLevel1").load("${pageContext.request.contextPath}/dev/devcategoryLevel1")
		if(${categoryLevel1>0}){
			$("#categoryLevel2").load("${pageContext.request.contextPath}/dev/devcategoryLevel2?parentId2="+${categoryLevel1});
		}
		$("#categoryLevel1").on("change",function () {
			if($(this).val()==0){
				$("#categoryLevel2").html("<option value='0'>--请选择--</option>")
				$("#categoryLevel3").html("<option value='0'>--请选择--</option>")
			}
			$("#categoryLevel2").load("${pageContext.request.contextPath}/dev/devcategoryLevel2?parentId2="+$("#categoryLevel1").val());
		})
		if(${categoryLevel2>0}){
			$("[name=categoryLevel3]").load("${pageContext.request.contextPath}/dev/devcategoryLevel3?parentId3="+${categoryLevel2});
		}
		$("#categoryLevel2").on("change",function(){
			if($(this).val()==0){
				$("#categoryLevel3").html("<option value='0'>--请选择--</option>")
			}
			$("[name=categoryLevel3]").load("${pageContext.request.contextPath}/dev/devcategoryLevel3?parentId3="+$("#categoryLevel2").val());
		})
		$("#devqueryStatus").load("${pageContext.request.contextPath}/dev/zhuangtai");
		$(".modifyAppInfo").on("click",function () {
			var obj=$(this);
			var AppInfoId=obj.attr("appinfoid")
			var zhuangtai=obj.attr("status")
			if(zhuangtai==4){
				alert("该APP应用的状态为：【已上架】不能修改");
			}else if(zhuangtai==5){
				alert("该APP应用的状态为：【已下架】不能修改");
			}else{
				window.location.href="${pageContext.request.contextPath}/dev/devupdatelist?AppInfoId="+AppInfoId;
			}
		})
		$(".addVersion").click(function () {
			var appinfoid=$(this).attr("appinfoid");
			location.href="${pageContext.request.contextPath}/dev/banbenadd?appid="+appinfoid;
		})
		$(".modifyVersion").click(function () {
			var appinfoid=$(this).attr("appinfoid")
			var versionid=$(this).attr("versionid")
			if(versionid==null||versionid==""){
				alert("没有版本信息不能修改，请先添加");
				return false;
			}
			location.href="${pageContext.request.contextPath}/dev/banbenmodify?appid="+appinfoid+"&versionid="+versionid;
		})
		$(".viewApp").click(function () {
			var appId=$(this).attr("appinfoid");
			location.href="${pageContext.request.contextPath}/dev/appchakan?appid="+appId;
		})
		$(".deleteApp").click(function () {
			var delName=$(this).attr("appsoftwarename");
			if(confirm("确定要删除APP应用["+delName+"]及其所有的版本吗？")){
				var delId=$(this).attr("appinfoid");
				var $obj=$(this).parent().parent().parent().parent().parent();
				$.get("${pageContext.request.contextPath}/dev/appdel","appid="+delId,function (data) {
					if(data.flag=="true"){
						$obj.remove()
						alert("删除成功");
					}else{
						alert("删除失败");
					}
				},"json")
			}
		})
		$(".saleSwichOpen").click(function () {
			var id=$(this).attr("appinfoid");
			var appInfoStatus=$("#appInfoStatus"+id);
			var obj=$(this);
			var statusName=appInfoStatus.html();
			var status;
			if(statusName=="已下架"||statusName=="审核通过"){
				obj.className="saleSwichOpen";
				appInfoStatus.html("已上架")
				appInfoStatus.parent().css({"background-color":"#1ABB9C","color":"#FFFFFF"})
				obj.html("下架")
				status=4;
			}else if(statusName=="已上架"){
				obj.className="saleSwichClose";
				appInfoStatus.html("已下架")
				appInfoStatus.parent().css({"background-color":"red","color":"#FFFFFF"})
				obj.html("上架")
				status=5;
			}
			$.get("${pageContext.request.contextPath}/dev/shangjia","id="+id+"&status="+status,function (data) {
				if(data.flag=="true"){
					// location.reload();
					if(statusName=="已下架"||statusName=="审核通过"){
						alert("上架成功")
					}else if(statusName=="已上架"){
						alert("下架成功");
					}
				}else{
					alert("上架失败")
				}
			},"json")
		})
		$
		$(".saleSwichClose").click(function () {
			var id=$(this).attr("appinfoid");
			var appInfoStatus=$("#appInfoStatus"+id);
			var obj=$(this);
			var statusName=appInfoStatus.html();
			var status;
			if(statusName=="已下架"){
				obj.className="saleSwichOpen";
				appInfoStatus.html("已上架")
				appInfoStatus.parent().css({"background-color":"#1ABB9C","color":"#FFFFFF"})
				obj.html("下架")
				status=4;
			}else if(statusName=="已上架"){
				obj.className="saleSwichClose";
				appInfoStatus.html("已下架")
				appInfoStatus.parent().css({"background-color":"red","color":"#FFFFFF"})
				obj.html("上架")
				status=5;
			}
			$.get("${pageContext.request.contextPath}/dev/shangjia","id="+id+"&status="+status,function (data) {
				if(data.flag=="true"){
					// location.reload();
					if(statusName=="已下架"){
						alert("上架成功")
					}else if(statusName=="已上架"){
						alert("下架成功");
					}
				}else{
					alert("下架失败")
				}
			},"json")
		})
	})
</script>